const { logger } = require('../utils');
const { knex, TABLE_NAME } = require('./db');

knex.schema.hasTable(TABLE_NAME.organization).then((exists) => {
  if (!exists) {
    console.log(`createTable: ${TABLE_NAME.organization}`);
    return knex.schema.createTable(TABLE_NAME.organization, (t) => {
      t.charset('utf8');
      t.uuid('id').primary();
      t.string('organizationName').notNullable();
      t.string('organizationOpenId').notNullable();
      t.string('uniformSocialCreditCode');
      t.string('proxyAppId');
    });
  }
})
  .catch((err) => {
    logger.error({
      message: err.message,
      stack: err.stack,
      Action: 'organization/createTable',
    });
    console.error(err);
  });

